package com.med.meddataintegrator.patient.controller;

import com.med.meddataintegrator.common.basic.response.JsonResult;
import com.med.meddataintegrator.common.pojo.dto.patinet.PatientQueryParams;
import com.med.meddataintegrator.patient.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/patient")
@Api(tags = "patient")
@Slf4j
@Validated
public class PatientController {

    @Autowired
    private PatientService patientService;

    @PostMapping("/list")
    @ApiOperation(value = "获取患者列表", notes = "返回所有患者的信息列表")
    public JsonResult list(@Valid @RequestBody PatientQueryParams params) {
        try {
            log.info("获取患者列表, 参数: {}", params);
            return patientService.getlist(params);
        } catch (Exception e) {
            log.error("获取患者列表时发生错误, 参数: {}", params, e);
            return JsonResult.fail("获取患者列表时发生错误: " + e.getMessage());
        }
    }
}
